<?php

namespace Rexzy\App;

class Db {
    static private $_instance;
    private $_db;  
    
    private function __construct() {
        $dbms = \Rexzy::getConfig( 'dbms' );
        $host = \Rexzy::getConfig( 'host' );
        $dbName = \Rexzy::getConfig( 'dbName' );
        $dbUser = \Rexzy::getConfig( 'dbUser' );
        $pass = \Rexzy::getConfig( 'dbPass' );
        $dns = "$dbms:host=$host;dbname=$dbName";
        $this->_db = new \Rexzy\Database\PDO( $dns, $dbUser, $pass );
    }
    
    /**
     * 获取 Db单例
     * 
     * @return object 
     */
    static function getInstance() {
        if ( !isset( self::$_instance ) ) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }
    
    /**
     * 封装类的 $this->_db 属性
     * 
     * @return object 返回实例的 PDO对象
     */
    public function db() {
        return $this->_db;
    }
}